package org.jxf.gps.jfinal.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.jxf.gps.jt808.message.Message;
import org.jxf.gps.jt808.server.GpsServer;

import com.jfinal.core.Controller;

public class MonitorController extends Controller{

	public void index(){
		Iterator itr = GpsServer.onlineTerminals.keySet().iterator();
		List termList = new ArrayList();
		while(itr.hasNext()){
			Map m = new HashMap();
			Object mdn = itr.next();
			Message msg = (Message)GpsServer.onlineTerminals.get(mdn).get("moMsg");
			m.put("mdn", mdn);
			m.put("msg", msg);
			termList.add(m);
		}		
		
		Iterator itr2 = GpsServer.orgSessionMap.keySet().iterator();
		List orgList = new ArrayList();
		while(itr2.hasNext()){
			Map m = new HashMap();
			Object org = itr2.next();
			List list = GpsServer.orgSessionMap.get(org);
			m.put("org", org);
			m.put("list", list);
			orgList.add(m);
		}		
	
		Iterator itr3 = GpsServer.sessionMessage.keySet().iterator();
		List sessionList = new ArrayList();
		while(itr3.hasNext()){
			Map m = new HashMap();
			Object session = itr3.next();
			List list = GpsServer.sessionMessage.get(session);
			m.put("session", session);
			m.put("list", list);
			sessionList.add(m);
		}		

		this.setAttr("termList", termList);
		this.setAttr("orgList", orgList);
		this.setAttr("sessionList", sessionList);
		
		this.setAttr("tcpConnCount", GpsServer.tcpConnCount);
		this.setAttr("tcpMsgRecvCount", GpsServer.tcpMsgRecvCount);
		this.setAttr("tcpMsgQCount", GpsServer.tcpMsgQCount);
		this.setAttr("tcpMsgRevErrCount", GpsServer.tcpMsgRevErrCount);
		this.setAttr("tcpExceptionCaught", GpsServer.tcpExceptionCaught);

	
	}

}
